import request from '@/utils/request'
// 加入购物车接口
export const addCartListAPI = (addCartList) => {
  return request({
    url: '/ios/ShoppingCart',
    method: 'POST',
    data: addCartList.value
  })
}

// 获取购物车接口
export const getCartListAPI = (userId) => {
  // 如果用户未登录，直接返回空数组
  if (userId == null) {
    return Promise.resolve({ data: [] })
  }

  // 请求参数是 userId
  return request({
    url: '/ios/ShoppingCart/list',
    params: { userId } // 把 userId 作为查询参数
  })
}

// 删除购物车
// ids: [String]
export const deleteCartListAPI = (ShoppingCartIDs) => {
  return request({
    url: `/ios/ShoppingCartDetails/${ShoppingCartIDs.join(',')}`,
    method: 'DELETE'
  })
}

//购物车添加到订单
export const addToOrderAPI = (data) => {
  return request({
    url: '/ios/ShoppingCartDetails/addToOrder',
    method: 'PUT',
    data
  })
}

// 合并购物车
export const mergeCartAPI = (data) => {
  return request({
    url: '/ios/ShoppingCart/merge',
    method: 'POST',
    data
  })
}

export const gobackCart = (ShoppingCartIDs) => {
  return request({
    url: `/ios/ShoppingCartDetails/${ShoppingCartIDs.join(',')}`,
    method: 'PUT'
  })
}
